#include <LPC214x.H>                       /* LPC214x definitions */

typedef unsigned char uc;

#define BUZZER 		(1 << 25)
#define BUZZER_DIR 	IO1DIR
#define BUZZER_SET 	IO1SET
#define BUZZER_CLR 	IO1CLR

#define SWITCH_1	(1 << 15)
#define SWITCH_PIN	IO0PIN
#define SWITCH_DIR	IO0DIR


void delay(int count);
void turn_on_buzzer(void);
void turn_off_buzzer(void);
uc read_switch(void);

int main (void) 
{
  SWITCH_DIR &=  ~SWITCH_PIN;		// Ensures the pin configured as input;   

  while (1)  
  {
  	if(read_switch())
	{
	  	turn_on_buzzer();
	   	delay(1000);
	 	turn_off_buzzer();
	   	delay(1000);
	}
  }
}

void delay(int count)
{
  int j=0,i=0;

  for(j=0;j<count;j++)
  {
    /* At 60Mhz, the below loop introduces
    delay of 1000 us */
    for(i=0;i<3500;i++);
  }
}

void turn_on_buzzer(void)
{    
  BUZZER_DIR |= BUZZER;
  BUZZER_CLR = BUZZER;	
}

void turn_off_buzzer(void)
{
   BUZZER_DIR |= BUZZER;
   BUZZER_SET = BUZZER;
}


uc read_switch(void)
{
   return (SWITCH_PIN & SWITCH_1) ? 0 : 1;
}
